#用于展示用户的已购商品
from parameter import my_orderlist
import tkinter as tk
from PIL import Image, ImageTk
from link import *
import visitorPage as vp

class orderList():
    def __init__(self, master=None, name=None):
        self.name = name
        self.window = master
        self.window.title('已购列表')
        self.window.geometry('550x833')
        self.create_page()

    def create_page(self):
        global image
        self.page = tk.Frame(self.window, width=550, height=833)
        self.page.pack()
        img = Image.open('emt.png')
        image = ImageTk.PhotoImage(img)
        label_img = tk.Label(self.page, image=image)
        label_img.pack()
        tk.Button(self.page, text='返回', font=('楷体', 18), bg='CornflowerBlue', fg='Moccasin', command=self.back).place(x=30, y=50, anchor='nw')
        tk.Label(self.page, text='用户{name}的已购列表'.format(name=self.name), font=('幼圆', 15), bg='FloralWhite', fg='OliveDrab').place(x=180, y=60, anchor='nw')
        self.goods()

    def goods(self):    
        obj = loginSearch()
        sql = my_orderlist(self.name)

        cursor = obj.conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()

        if len(data) == 0:
            tk.Label(self.page, text='对不起，您的已购列表为空', font=('幼圆', 25), bg='FloralWhite', fg='OliveDrab').place(x=100, y=100, anchor='nw')

        col = 200

        for i in range(len(data)):
            tk.Label(self.page, text=data[i][0], font=('幼圆', 12), bg='FloralWhite', fg='OliveDrab').place(x=15, y=col, anchor='nw')
            col = col + 30

        obj.close_conn()

    def back(self):
        self.page.destroy()
        vp.visitorPage(self.window, self.name)
